from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-01 14:02:35.431299
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 01, Sep, 2022
Time: 14:02:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2798
Nobs: 766.000 HQIC: -50.6152
Log likelihood: 9773.84 FPE: 8.45197e-23
AIC: -50.8251 Det(Omega_mle): 7.52075e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300872 0.054666 5.504 0.000
L1.Burgenland 0.106720 0.036360 2.935 0.003
L1.Kärnten -0.106758 0.019319 -5.526 0.000
L1.Niederösterreich 0.205512 0.075998 2.704 0.007
L1.Oberösterreich 0.113510 0.073617 1.542 0.123
L1.Salzburg 0.253087 0.038910 6.504 0.000
L1.Steiermark 0.036118 0.050739 0.712 0.477
L1.Tirol 0.106788 0.041093 2.599 0.009
L1.Vorarlberg -0.060463 0.035327 -1.712 0.087
L1.Wien 0.049488 0.065458 0.756 0.450
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059956 0.113571 0.528 0.598
L1.Burgenland -0.034937 0.075539 -0.463 0.644
L1.Kärnten 0.047393 0.040136 1.181 0.238
L1.Niederösterreich -0.174028 0.157887 -1.102 0.270
L1.Oberösterreich 0.394366 0.152941 2.579 0.010
L1.Salzburg 0.290289 0.080837 3.591 0.000
L1.Steiermark 0.105490 0.105413 1.001 0.317
L1.Tirol 0.314628 0.085371 3.685 0.000
L1.Vorarlberg 0.026831 0.073394 0.366 0.715
L1.Wien -0.022762 0.135991 -0.167 0.867
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191004 0.028109 6.795 0.000
L1.Burgenland 0.089628 0.018696 4.794 0.000
L1.Kärnten -0.008708 0.009934 -0.877 0.381
L1.Niederösterreich 0.259553 0.039078 6.642 0.000
L1.Oberösterreich 0.134474 0.037853 3.552 0.000
L1.Salzburg 0.045346 0.020007 2.266 0.023
L1.Steiermark 0.017963 0.026090 0.689 0.491
L1.Tirol 0.093753 0.021130 4.437 0.000
L1.Vorarlberg 0.058394 0.018165 3.215 0.001
L1.Wien 0.119661 0.033658 3.555 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108548 0.028556 3.801 0.000
L1.Burgenland 0.047649 0.018994 2.509 0.012
L1.Kärnten -0.014755 0.010092 -1.462 0.144
L1.Niederösterreich 0.191659 0.039699 4.828 0.000
L1.Oberösterreich 0.290315 0.038455 7.549 0.000
L1.Salzburg 0.111560 0.020326 5.489 0.000
L1.Steiermark 0.102616 0.026505 3.872 0.000
L1.Tirol 0.110444 0.021466 5.145 0.000
L1.Vorarlberg 0.069684 0.018454 3.776 0.000
L1.Wien -0.018414 0.034194 -0.539 0.590
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130802 0.051861 2.522 0.012
L1.Burgenland -0.051349 0.034494 -1.489 0.137
L1.Kärnten -0.040263 0.018328 -2.197 0.028
L1.Niederösterreich 0.171867 0.072097 2.384 0.017
L1.Oberösterreich 0.140380 0.069838 2.010 0.044
L1.Salzburg 0.288148 0.036913 7.806 0.000
L1.Steiermark 0.032260 0.048135 0.670 0.503
L1.Tirol 0.161853 0.038984 4.152 0.000
L1.Vorarlberg 0.100217 0.033514 2.990 0.003
L1.Wien 0.068009 0.062099 1.095 0.273
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056010 0.041293 1.356 0.175
L1.Burgenland 0.040323 0.027465 1.468 0.142
L1.Kärnten 0.050441 0.014593 3.456 0.001
L1.Niederösterreich 0.220364 0.057406 3.839 0.000
L1.Oberösterreich 0.282832 0.055608 5.086 0.000
L1.Salzburg 0.045463 0.029392 1.547 0.122
L1.Steiermark -0.000650 0.038327 -0.017 0.986
L1.Tirol 0.147902 0.031040 4.765 0.000
L1.Vorarlberg 0.072942 0.026685 2.733 0.006
L1.Wien 0.085174 0.049445 1.723 0.085
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179763 0.049451 3.635 0.000
L1.Burgenland -0.005855 0.032891 -0.178 0.859
L1.Kärnten -0.061276 0.017476 -3.506 0.000
L1.Niederösterreich -0.082701 0.068747 -1.203 0.229
L1.Oberösterreich 0.195980 0.066593 2.943 0.003
L1.Salzburg 0.056477 0.035198 1.605 0.109
L1.Steiermark 0.230767 0.045899 5.028 0.000
L1.Tirol 0.493902 0.037172 13.287 0.000
L1.Vorarlberg 0.047904 0.031957 1.499 0.134
L1.Wien -0.052809 0.059213 -0.892 0.372
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166581 0.056782 2.934 0.003
L1.Burgenland -0.010430 0.037767 -0.276 0.782
L1.Kärnten 0.067140 0.020067 3.346 0.001
L1.Niederösterreich 0.207156 0.078939 2.624 0.009
L1.Oberösterreich -0.071002 0.076466 -0.929 0.353
L1.Salzburg 0.211556 0.040416 5.234 0.000
L1.Steiermark 0.115387 0.052703 2.189 0.029
L1.Tirol 0.071880 0.042683 1.684 0.092
L1.Vorarlberg 0.121532 0.036694 3.312 0.001
L1.Wien 0.121828 0.067991 1.792 0.073
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358724 0.032811 10.933 0.000
L1.Burgenland 0.005728 0.021824 0.262 0.793
L1.Kärnten -0.023201 0.011596 -2.001 0.045
L1.Niederösterreich 0.214051 0.045614 4.693 0.000
L1.Oberösterreich 0.188460 0.044185 4.265 0.000
L1.Salzburg 0.046239 0.023354 1.980 0.048
L1.Steiermark -0.015694 0.030454 -0.515 0.606
L1.Tirol 0.106249 0.024664 4.308 0.000
L1.Vorarlberg 0.073574 0.021204 3.470 0.001
L1.Wien 0.047323 0.039288 1.205 0.228
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040194 0.148451 0.192187 0.157662 0.124210 0.113023 0.065839 0.221831
Kärnten 0.040194 1.000000 -0.003907 0.132797 0.041533 0.095831 0.430975 -0.052280 0.100613
Niederösterreich 0.148451 -0.003907 1.000000 0.337456 0.151189 0.298677 0.107470 0.183028 0.323044
Oberösterreich 0.192187 0.132797 0.337456 1.000000 0.228147 0.330671 0.172155 0.167824 0.264135
Salzburg 0.157662 0.041533 0.151189 0.228147 1.000000 0.147582 0.122210 0.147339 0.133065
Steiermark 0.124210 0.095831 0.298677 0.330671 0.147582 1.000000 0.151303 0.138404 0.079175
Tirol 0.113023 0.430975 0.107470 0.172155 0.122210 0.151303 1.000000 0.115053 0.152530
Vorarlberg 0.065839 -0.052280 0.183028 0.167824 0.147339 0.138404 0.115053 1.000000 0.006578
Wien 0.221831 0.100613 0.323044 0.264135 0.133065 0.079175 0.152530 0.006578 1.000000